package com.zhiche.lisa.bms.controller.psup;


import com.baomidou.mybatisplus.plugins.Page;
import com.zhiche.lisa.bms.dao.model.psup.PsupBaseFleet;
import com.zhiche.lisa.bms.service.psup.PsupBaseFleetService;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 人送基础车队信息 前端控制器
 * </p>
 *
 * @author linbao
 * @since 2019-07-02
 */
@RestController
@RequestMapping("/psupBaseFleet")
@Api(description = "人送基础车队信息", tags = "人送基础车队信息")
@Slf4j
public class PsupBaseFleetController extends PsupSdBaseController {

    @Autowired
    private PsupBaseFleetService psupBaseFleetService;

    /**
     * 分页查询
     *
     * @return
     */
    @PostMapping(value = "/querySdBaseFleetPage")
    @ApiOperation(value = "人送基础车队信息的分页查询", notes = "人送基础车队信息的分页查询", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PsupBaseFleet.class),
            @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<PsupBaseFleet>> querySdBaseFleetPage(@RequestBody Page<PsupBaseFleet> page) {
        log.info("PsupBaseFleetController.querySdBaseFleetPage param: {}", page);
        RestfulResponse<Page<PsupBaseFleet>> resultResponse = getSuccessResponse();
        try {
            resultResponse.setData(psupBaseFleetService.queryBaseFleetPage(page));
        } catch (BaseException e) {
            log.error("PsupBaseFleetController.querySdBaseFleetPage error:{}", e);
            setBaseExceptionResponse(resultResponse, e.getMessage());
        } catch (Exception e) {
            log.error("PsupBaseFleetController.querySdBaseFleetPage error:{} ", e);
            setErrorResponse(resultResponse);
        }
        return resultResponse;
    }

    /**
     * 人送基础信息的新增
     *
     * @return
     */
    @PostMapping(value = "/createBaseFleetInfo")
    @ApiOperation(value = "人送基础车队信息的新增", notes = "人送基础车队信息的新增", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = PsupBaseFleet.class),
            @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Object> createBaseFleetInfo(@RequestBody PsupBaseFleet psupBaseFleet) {
        log.info("PsupBaseFleetController.createBaseFleetInfo param: {}", psupBaseFleet);
        RestfulResponse<Object> resultResponse = getSuccessResponse();
        try {
            psupBaseFleetService.createBaseFleet(psupBaseFleet);
        } catch (BaseException e) {
            log.error("PsupBaseFleetController.createBaseFleetInfo error:{}", e);
            setBaseExceptionResponse(resultResponse, e.getMessage());
        } catch (Exception e) {
            log.error("PsupBaseFleetController.createBaseFleetInfo error:{} ", e);
            setErrorResponse(resultResponse);
        }
        return resultResponse;
    }
}

